<?php
/**
 *商品库存调拨申请模型
 */
class Backup_Model_StockTransferApply extends Application_Model_StoryTransferApply {

	/**
	 * 人工审核通过调拨申请
	 * @return [type] [description]
	 */
	public function agreeByAdmin($transferApplyId) {
		return $this->_agree($transferApplyId, self::ADMIN_AGREE);
	}

	/**
	 * 调拨申请人工驳回
	 * @return [type] [description]
	 */
	public function rejectByAdmin($transferApplyId) {
		return $this->_reject($transferApplyId, self::ADMIN_REJECT);
	}

	/**
	 * 获取待审核列表
	 * @return [type] [description]
	 */
	public function getWaitCheckApply() {
		return $this->_getApplyByStatus('待审核');
	}

	/**
	 * 获取产品 从 出库仓$fromTransferWarehouse 到入库仓 $toTransferWarehouse 的上一次审核结果
	 * @param  [type] $goodsSn               [description]
	 * @param  [type] $fromTransferWarehouse [description]
	 * @param  [type] $toTransferWarehouse   [description]
	 * @return [type]                        [description]
	 */
	public function getProductLastApplyCheckResult($goodsSn, $fromTransferWarehouse, $toTransferWarehouse, $create_date) {
		$where = $this->db->quoteInto("goods_sn=?", $goodsSn);
		$where .= ' AND ' . $this->db->quoteInto("from_warehouse = ?", $fromTransferWarehouse);
		$where .= ' AND ' . $this->db->quoteInto("to_warehouse = ?", $toTransferWarehouse);
		$where .= ' AND ' . $this->db->quoteInto("create_date < ?", $create_date);
		$where .= ' AND ' . $this->db->quoteInto("status != ?", '待审核');

		return $this->db->fetchOne('select status from b_stock_transfer_apply where ' . $where . ' order by create_date desc limit 1');
	}
}